import requests
#确定url
url = 'https://www.baidu.com'
#设置代理ip
proxies = {
    'http':'139.9.2.31:8081'
}

#构造请求头
headers={'User-Agent':'Mozilla/5.0 (Windows NT 10.0; Win64; x64) '
                      'AppleWebKit/537.36 (KHTML, like Gecko) '
                      'Chrome/96.0.4664.55 Safari/537.36 Edg/96.0.1054.43'}

#发送请求
response=requests.get(url,proxies=proxies,headers=headers)

with open('代理ip.html','wb') as file_build:
    file_build.write(response.content)